<template>
	<view class="login">
		<view class="text">
			欢迎登陆核销系统
		</view>
		<view class="logo">
			<image src="../../static/logo.png" mode=""></image>
		</view>
		
		<view class="shuruk">
			<view class="flexs">
				<image src="../../static/zhanghao.png" mode=""></image>
				<input type="text" placeholder="账号" v-model="number" />
			</view>
			<view class="flexs">
				<image src="../../static/mima.png" mode=""></image>
				<view class="inputflex">
					<input v-model="pwd" :password="isshow" placeholder="密码" />
					<view @click="isshow =!isshow" style="width: 80rpx;display: flex;justify-content: center;align-items: center;">
						<uni-icons :type="isshow?'eye-slash' : 'eye'" size="24" ></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="btn" @click="toLogin">
			登录
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				number:'',
				pwd:'',
				logoImg:'',
				isshow: true,
			}
		},
		onLoad(options) {
			if(uni.getStorageSync('user')){
				let user = uni.getStorageSync('user')
				this.number = user.mobile
				this.pwd = user.password
			}
			// this.confirmJdk()
		},
		methods: {
			toLogin(){
				if(this.number==''||this.pwd==''){
					uni.showToast({
						title:'不能为空',
						icon:'none'
					})
					return
				}
				let rand = Math.floor(Math.random()*100)
				this.$post('index/login',{
					mobile:this.number,
					password:this.pwd,
					rand:rand
				}).then(res=>{
					if(res.code==0){
						let data = res.data
						data.password = this.pwd
						uni.setStorageSync('user',data)
						uni.navigateTo({
							url:'index'
						})
						// window.location.href = 'http://localhost:8080/pages/index/index'
					}
				})
			},
			confirmJdk() {
				let locationHref = location.href.split('#')[0];
				this.$post('register/Scancode',{
					url:locationHref
				}).then(data => {
					wx.config({
						appId: data.data.appId, // 和获取Ticke的必须一样------必填，公众号的唯一标识
						timestamp: data.data.timestamp, // 必填，生成签名的时间戳
						nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
						signature: data.data.signature, // 必填，签名，见附录1
						jsApiList: [
							'scanQRCode'
						]
					});
					wx.ready(() => {
						wx.checkJsApi({
							jsApiList: ['scanQRCode'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
							success: (res) => {
								console.log('返回信息')
								console.log(res)
								// 以键值对的形式返回，可用的api值true，不可用为false
								// 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
							}
						});
					})
				})
			},
			scanQRCode() {
				wx.scanQRCode({
					needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
					scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
					success:(res)=> {
						console.log(res);
						console.log('扫码')
						location.href = res.resultStr
						// var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
						// window.location.href = result //安卓机型跳转渲染有问题 所以要加这句
					}
				});
			}
		}
	}
</script>

<style lang="less">
	.shuruk {
		z-index: 2;
		margin-top: 120rpx;
		.flexs {
			margin: 0 auto;
			width: 481rpx;
			height: 41rpx;
			background: #FFFFFF;
			border-radius: 40rpx;
			display: flex;
			align-items: center;
			padding: 20rpx;
			margin-bottom: 43rpx;
			border: 1px solid #eee;
		}
		.inputflex{
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			input{
				flex: 1;
			}
		}
		image {
			width: 42rpx;
			height: 42rpx;
			margin-right: 10rpx;
		}
	
	}
	.login{
		padding-top: 120rpx;
		.logo{
			width: 134rpx;
			height: 134rpx;
			opacity: 1;
			// background: #3a67e8;
			border-radius: 50%;
			margin: 0 auto;
			overflow: hidden;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.text{
			text-align: center;
			font-size: 36rpx;
			font-weight: 700;
			color: #333333;
			margin-bottom: 32rpx;
		}
		.btn{
			width: 497rpx;
			height: 86rpx;
			line-height: 88rpx;
			opacity: 1;
			background: #FF7416;
			border-radius: 44rpx;
			text-align: center;
			font-size: 34rpx;
			font-weight: 500;
			color: #ffffff;
			margin: 0 auto;
			margin-top: 99rpx;
		}
	}
</style>
